import axios from "axios";

const timeout = 1000;
const baseURL = import.meta.env.VITE_API_BASE_URL;

const http = axios.create({
    timeout,
    baseURL
})

http.interceptors.request.use(config => {
    return config
})

http.interceptors.response.use(response => {

    if (response.status !== 200) return Promise.reject(new Error(response.statusText))
    
    const result = response.data

    if (!result) return Promise.reject(new Error('请求失败'))

    if (result.code !== 200) return Promise.reject(new Error(result.message))
    
    return result
})


export default http